import React from 'react';
import loadjs from 'loadjs';
import { workflowPublicFiles } from '../constants/fileConfig';
import {observer,inject} from "mobx-react/index";
@observer
export default class TagTypeSelectDialog extends React.Component{
    constructor(props){
        super(props);
        
        this.state = {hasLoad: false,store: null};
    }
    componentDidMount(){
        const init = () =>{
            const { FollowTypeSettingStore } = window.weaWorkflowPublic;
            const store = new FollowTypeSettingStore();
            this.setState({hasLoad: true,store:store});
            window.followTypeSettingStore = store//抛出store给unitll用
        }
        loadjs.isDefined('workflowPublic') ? loadjs.ready('workflowPublic', init) : loadjs(workflowPublicFiles, 'workflowPublic', init);
    }

    addBtnClick=(value)=>{
        const { store} = this.state;
        const {saveAttentionTypeSet,getAttentionTypeSet} = store
        saveAttentionTypeSet({showname:value,src:'saveData2'})
    }
    onVisibleChange=()=>{
        const {curStore} = this.props;
        curStore.followTypeSelectShow = false
    }
    followMakeSure=()=>{//点击确定之后刷新列表
        const {curStore,refresh,refreshTabs, loadCount} = this.props;
        //将此方法传达子组件内，然后等保存结束之后调用
        typeof refresh =="function" && refresh();
        // typeof refreshTabs=="function" && refreshTabs();
        typeof this.props.loadCount =="function" && this.props.loadCount({method:"all"})
        curStore.followTypeSelectShow = false
    }
    render(){
        const { hasLoad ,store} = this.state;
        const {curStore} = this.props;
        if(hasLoad){
            const {TagTypeSelectDialog} = window.weaWorkflowPublic;
            return (
                <TagTypeSelectDialog ecId={`${this && this.props && this.props.ecId || ''}_TagTypeSelectDialog@rl4gkp`}  
                    followTypeSettingStore={store}
                    FollowRequestid={curStore.FollowRequestid}
                    cancelCallBack={(value)=>{this.onVisibleChange()}}
                    data={store.tagList} 
                    visible={curStore.followTypeSelectShow} 
                    onVisibleChange={this.onVisibleChange} 
                    addBtn={this.addBtnClick}
                    isSingle = {curStore.isSingle}
                    refresh={this.props.refresh}
                    makeSureCallBack={()=>{this.followMakeSure()}}   
                />);
        }else{
            return ( <div></div>);
        }
    }
}